class Solution {

  solution1(A){
      let n = A.length;
      let dp = [1];
      //init
      for (let i = 1; i <= n; i++) {
          dp.push(0)
      }
      for (let i = 1; i <= n; i++) {
          if(i === 1){
              dp[i] = A[i - 1];
              continue;
          }
          if (i===2){
              dp[i] = dp[i - 1] + A[i - 1];
              continue
          }
          if (A[i - 1] === 0){
              dp[i] = dp[i - 1] ;
          }else {

              for (let j = i; j >= 2; j--) {
                  if (A[j - 2] === 0){
                      if(j === 2){
                          dp[i]++
                      }else {
                          dp[i] += dp[j - 1]
                      }
                  }else {
                      dp[i] += dp[j - 1]
                      break;
                  }
              }
          }
      }
      return dp[n]
  }

}
//[1,0,1,1]
console.log(new Solution().solution1([0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0]))

